﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Diagnostics;
using System.Windows.Forms;
using Contract;
using System.IO;

namespace client
{
    public partial class Login : Form
    {
        public static string PCN;
        public static IDataUploader Proxy;
        public NetTcpBinding binding;
        EndpointAddress address;
        ChannelFactory<IDataUploader> channel;
        public Login()
        {
            InitializeComponent();
            binding = new NetTcpBinding();
            binding.TransferMode = TransferMode.Streamed;
            binding.SendTimeout = TimeSpan.MaxValue;
            binding.MaxReceivedMessageSize = int.MaxValue;
            address = new EndpointAddress("net.tcp://127.0.0.1:5000/DataUploader");
            channel = new ChannelFactory<IDataUploader>(binding, address);

            // create a hosting process for Service
            //ServiceHost host = new ServiceHost(typeof(CallBack));
            //NetTcpBinding binding = new NetTcpBinding();
            //binding.TransferMode = TransferMode.Buffered;
            //binding.ReceiveTimeout = TimeSpan.MaxValue;
            //binding.MaxReceivedMessageSize = int.MaxValue;

            //host.AddServiceEndpoint(typeof(ICallBack), binding,
            //new Uri("net.tcp://localhost:5000/DataUploader"));

            //host.Open();
            
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IDataUploader Proxy = channel.CreateChannel();
            PCN = textBox1.Text.Trim();
            string Password = textBox2.Text.Trim();
            
         
                if (PCN == "" || Password == "")
                {
                    MessageBox.Show("Can't be empty");
                }
                else
                {
                    if (Proxy.Login(PCN, Password))
                    {
                        Form1 f1 = new Form1(PCN);
                        f1.Show();
                    }
                    else
                        MessageBox.Show("fail-remote");
                }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Register fr = new Register();
            fr.Show();
        }
    }
}
